package com.lagou.util;

/**
 * @author Kirito
 * @description: Http协议工具类，提供Http响应头信息
 * @date 2020/04/24
 */
public class HttpProtocolUtil {

    private HttpProtocolUtil() {
        throw new RuntimeException("Can not be instantiated");
    }

    /**
     * 获取响应码200请求头
     *
     * @return String
     */
    public static String getHttpHeader200(long contentLength) {
        return "HTTP/1.1 200 OK \n" +
                "content-type: text/html; charset=UTF-8 \n" +
                "content-length: " + contentLength + "\n" +
                "\r\n";
    }

    /**
     * 获取响应码404请求头
     *
     * @return String
     */
    public static String getHttpHeader404() {
        final String response = "<h1>404 Not Found</h1>";
        return "HTTP/1.1 404 Not Found \n" +
                "content-type: text/html; charset=UTF-8 \n" +
                "content-length: " + response.getBytes().length + "\n" +
                "\r\n" + response;
    }
}
